import { useState, useEffect } from 'react';
const baseUrl = 'https://cnodejs.org/api/v1';

const useList = () => {
    const [list, setList] = useState([]);
    const [loading, setLoading] = useState(false);
    const [tab, setTab] = useState('');
    const handleTab = tab=>setTab(tab);
    useEffect(() => {
        setLoading(true);
        fetch(`${baseUrl}/topics?tab=${tab}&page=${1}`)
            .then(res => res.json())
            .then(res => {
                console.log(res);
                setList(res.data);
                setLoading(false);
            })
    }, [tab])
    return [list, loading, handleTab]
}
export default useList;